<?php
session_start ();
// 判断用户是否已经登录
if (! isset ( $_SESSION ["userinfo"] ) and empty ( $_SESSION ["userinfo"] ["userid"] )) {
	header ( "location:../index.php" );
	session_unset ();
	session_destroy ();
	exit ();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="./Resource/Style/base.yy.css" rel="stylesheet"
	type="text/css" />
	<?php
	require_once '../tools/SqlHelper.class.php';
	$userid = $_SESSION ["userinfo"] ["userid"];
	if (isset ( $_POST ['user_submit'] ) and $_POST ['user_submit'] == '发送') {
		// 获取浏览器发过来的页面数据
		$editMsg = $_POST ['editMsg'];
		$send_user_id = $_POST ['user_receiver_id'];
		$send_type = $_POST ['send_type'];
		// $userid = "xufeng520";
		$sql = "INSERT INTO `message_tb` (`user_receiver_id`, `user_send_id`, `ms_content`) VALUES ('$send_user_id', '$userid', '$editMsg')";
		$sqlHelper = new SqlHelper ();
		$row = $sqlHelper->execute_dql ( $sql );
	}
	if (isset ( $_GET ['send_user_id'] )) {
		$send_user_id = $_GET ['send_user_id'];
		$send_type = $_GET ['send_type'];
	} else if (isset ( $_GET ['_id'] )) {
		$_id = $_GET ['_id'];
		$send_user_id = $_GET ['send_id'];
		$send_type = $_GET ['send_type'];
		$sql = "DELETE FROM `message_tb` WHERE `message_id`='$_id'";
		$sqlHelper = new SqlHelper ();
		$row = $sqlHelper->execute_dql ( $sql );
	}
	// $send_user_id = "xiaoyan";
	$username = $_SESSION ["userinfo"] ["username"];
	// $username = "许峰";
	// $userid = "xufeng520";
	$sqlHelper = new SqlHelper ();
	
	$sql = "select user_name from `user_tb` where `user_id`='$send_user_id'";
	$row = $sqlHelper->execute_dql ( $sql );
	$res = mysql_fetch_array ( $row );
	$send_user_name = $res ['user_name'];
	
	$sql = "select ps_sex,ps_birthday_year,ps_apartment,ps_Icon,ps_education from `personal_data_tb` where `user_id` = '$send_user_id'";
	$row = $sqlHelper->execute_dql ( $sql );
	$res = mysql_fetch_array ( $row );
	$ps_sex = $res ['ps_sex'];
	if ($ps_sex == "0") {
		$ps_sex = "男";
	} else {
		$ps_sex = "女";
	}
	$ps_education = $res ['ps_education'];
	if ($ps_education == "5") {
		$ps_education = "初中及以下";
	} else if ($ps_education == "1") {
		$ps_education = "高中及中专";
	} else if ($ps_education == "2") {
		$ps_education = "大专";
	} else if ($ps_education == "3") {
		$ps_education = "本科";
	} else if ($ps_education == "4") {
		$ps_education = "硕士及以上";
	}
	$ps_birthday_year = $res ['ps_birthday_year'];
	$now_data = getdate ();
	$ps_birthday_year = ($now_data ["year"] - ( int ) $ps_birthday_year);
	$ps_apartment = $res ['ps_apartment'];
	$ps_marry_condition = $res ['ps_marry_condition'];
	if ($ps_marry_condition == "1") {
		$ps_marry_condition = "未婚";
	} else if ($ps_marry_condition == "2") {
		$ps_marry_condition = "离异";
	} else if ($ps_marry_condition == "3") {
		$ps_marry_condition = "丧偶";
	}
	$ps_Icon = $res ['ps_Icon'];
	?>
<title>信息列表</title>
<link href="./Resource/Style/talk.yy.css" rel="stylesheet"
	type="text/css" />
</head>
<body>
	<div class="Pm">
		<span><em></em>有缘提醒：请选择自己熟悉的环境见面，不要与刚认识的异性有任何金钱来往，以防被骗。</span> <a
			href="<?php
			if ($send_type == "1") {
				echo "./MyEail.php";
			} else if ($send_type == "2") {
				echo "./MyAttention.php";
			} else if ($send_type == "3") {
				echo "./RecentContacts.php";
			}
			?>">返回列表</a>
	</div>
	<div class="Pm_user user_info">
		<p>
			<a target="new" class="showHref"
				title="点击进入<?php echo $send_user_name;?>的空间"
				href="../PersonalSpace/PersonalSpace.php?user_id=<?php echo $send_user_id;?>"><?php echo $send_user_name;?>
			<img width="79" height="97" class="showHref"
				src="<?php
				if ($ps_Icon == "0") {
					$user_img_path = "../PersonalPhoto/Images/nohead_new.jpg";
					echo $user_img_path;
				} else {
					$user_img_path = "../PersonalPhoto/" . $send_user_id . "/" . $ps_Icon;
					echo $user_img_path;
				}
				?>"
				title="点击进入<?php echo $send_user_name;?>的空间" /> </a>
		</p>
		<dl>
			<dt>
				<a target="new" class="showHref"
					title="点击进入<?php echo $send_user_name;?>的空间"
					href="../PersonalSpace/PersonalSpace.php?user_id=<?php echo $send_user_id;?>"><?php echo $send_user_name;?></a>
			</dt>
			<dd class="dd_info">
			<?php echo $ps_sex."  ".$ps_birthday_year." ".$ps_apartment."  ".$ps_marry_condition."  ".$ps_education;?>
			</dd>
			<dd>
				<font><em></em>在线状态： <a href="#" title="暂未开发">立即查看</a> </font>
			</dd>
			<dd>
				<strong></strong> <a id="reportUser" title="举报" href="#">举报</a> <span>|</span>
				<a href="#" title="加入黑名单" class="hate addBlack">加黑</a>
			</dd>
		</dl>
	</div>
	<div class="Pm_info mail_info talk">
	<?php
	$sql = "select * from `message_tb` where (`user_send_id`='$send_user_id' and `user_receiver_id` = '$userid') or (`user_send_id`='$userid' and `user_receiver_id` = '$send_user_id')";
	$row = $sqlHelper->execute_dql ( $sql );
	while ( $res = mysql_fetch_assoc ( $row ) ) {
		$send_user_id_w = $res ['user_send_id'];
		if ($send_user_id_w == $send_user_id) {
			$send_user_name_w = $send_user_name;
		} else {
			$send_user_name_w = $username;
		}
		$ms_id = $res ['message_id'];
		$ms_time = $res ['ms_time'];
		$ms_content = $res ['ms_content'];
		echo "<dl class='msg_item girl first fireFlowerFlg'>";
		echo "<dt>";
		echo "<font>$send_user_name_w</font><span>$ms_time</span>";
		echo "<a href='./ReadMessage.php?_id=" . $ms_id . "&send_id=" . $send_user_id_w . "&send_type=" . $send_type . "' style='float:right;font-size:16px;margin-right:16px'>删除</a>";
		echo "</dt>";
		echo "<dd>$ms_content</dd>";
		echo "</dl>";
	} // 关闭连接
	mysql_free_result ( $row );
	$sqlHelper->close_connect ();
	?>
	</div>
	<div class="send send_step1">
		<div class="reply"></div>
		<form action="./ReadMessage.php" method="post">
			<input type="hidden" name="user_receiver_id"
				value="<?php echo $send_user_id;?>"> <input type="hidden"
				name="send_type" value="<?php echo $send_type;?>">
			<textarea class="send_info" name="editMsg"
				style="width: 720px; height: 100px;"></textarea>
			<div class="send_btn">
				<font>快捷发送：<span>Ctrl+Enter</span></font> <input
					class="send_a sendMail" name=" user_submit" type="submit"
					value="发送" style="background-color: #01CBD3; border: 0;" />
			</div>
		</form>
	</div>
</body>
</html>